from sqlalchemy import Column, String, BigInteger, Float
from sqlalchemy.ext.declarative import declarative_base

# 创建对象的基类:
Base = declarative_base()
# 定义Stock对象:
class Stock(Base):
    # 表的名字:
    __tablename__ = 'stock'

    # 表的结构:
    ts_code = Column(String(20), primary_key=True)
    symbol = Column(String(20))
    name = Column(String(20))
    area = Column(String(10))
    industry = Column(String(20))
    # enname = Column(String(20))
    market = Column(String(20))
    # exchange = Column(String(20))
    # curr_type = Column(String(20))
    # list_status = Column(String(1))
    list_date = Column(String(20))
    # delist_date = Column(String(20))
    # is_hs = Column(String(1))

    def __repr__(self):
        return "<Stock(ts_code='%s', symbol='%s', name='%s', area='%s', industry='%s', market='%s', list_date='%s')>" % (
            self.ts_code, self.symbol, self.name, self.area, self.industry, self.market, self.list_date)
    # def __repr__(self):
    #     return "<Stock(ts_code='%s', symbol='%s', name='%s', area='%s', industry='%s', enname='%s', market='%s', exchange='%s', curr_type='%s', list_status='%s', list_date='%s', delist_date='%s', is_hs='%s')>" % (
    #         self.ts_code, self.symbol, self.name, self.area, self.industry, self.enname, self.market, self.exchange, self.curr_type, self.list_status, self.list_date, self.delist_date, self.is_hs)



# 定义账务指标对象
class FinaIndicator(Base):
    # 表的名字:
    __tablename__ = 'fina_indicator'

    # 表的结构:
    id = Column(BigInteger(), primary_key=True)
    ts_code = Column(String(20))
    trade_date = Column(String(20))
    close = Column(Float())
    turnover_rate = Column(Float())
    turnover_rate_f = Column(Float())
    volume_ratio = Column(Float())
    pe = Column(Float())
    pe_ttm = Column(Float())
    pb = Column(Float())
    ps = Column(Float())
    ps_ttm = Column(Float())
    dv_ratio = Column(Float())
    dv_ttm = Column(Float())
    total_share = Column(Float())
    float_share = Column(Float())
    free_share = Column(Float())
    total_mv = Column(Float())
    circ_mv = Column(Float())

    def __repr__(self):
        return "<Stock(ts_code='%s', trade_date='%s', close='%s', turnover_rate='%s', turnover_rate_f='%s', volume_ratio='%s', pe='%s', pe_ttm='%s', pb='%s', ps='%s', ps_ttm='%s', dv_ratio='%s', dv_ttm='%s', total_share='%s', float_share='%s', free_share='%s', total_mv='%s', circ_mv='%s')>" % (
            self.ts_code, self.trade_date, self.close, self.turnover_rate, self.turnover_rate_f, self.volume_ratio, self.pe, self.pe_ttm, self.pb, self.ps, self.ps_ttm, self.dv_ratio, self.dv_ttm, self.total_share, self.float_share, self.free_share, self.total_mv, self.circ_mv)


# 定义股市交易日期
class TradeCal(Base):
    # 表的名字:
    __tablename__ = 'trade_cal'

    # 表的结构:
    cal_date = Column(String(20), primary_key=True)
    exchange = Column(String(10))
    is_open = Column(String(5))
    pretrade_date = Column(String(20))

    def __repr__(self):
        return "<Stock(cal_date='%s', exchange='%s', is_open='%s', pretrade_date='%s')>" % (
            self.cal_date, self.exchange, self.is_open, self.pretrade_date)




# Base.metadata.create_all()